<?php

class OnlineAffidavitController extends Controller {

    public function actionIndex() {
        $this->layout = '//layouts/staticPage';

        $model = new AmanStudentDetails();


        $amanStudentParentsDetail = new AmanStudentParentsDetail();
        $amanStudentCollegeDetails = new AmanStudentCollegeDetails();
        $amanStudentCourseDetails = new AmanStudentCourseDetails();
        $amanStudentCollegeDetails->gender = 1;
        $model->gender = 1;
        $this->render('index', array(
            'model' => $model,
            'amanStudentParentsDetail' => $amanStudentParentsDetail,
            'amanStudentCollegeDetails' => $amanStudentCollegeDetails,
            'amanStudentCourseDetails' => $amanStudentCourseDetails,
        ));
    }

    public function actionSaveFormData() {
        $this->layout = false;

        if (isset($_POST['AmanStudentDetails'])) {
            $amanStudentDetails = new AmanStudentDetails();
            $amanStudentDetails->setAttributes($_POST['AmanStudentDetails']);
            if ($amanStudentDetails->save(false)) {
                //

                $amanStudentParentsDetails = new AmanStudentParentsDetail();
                $amanStudentParentsDetails->setAttributes($_POST['AmanStudentParentsDetail']);
                $amanStudentParentsDetails->setAttribute('student_details_id', $amanStudentDetails->id);
                $amanStudentParentsDetails->save(false);
                //

                $amanStudentCollegeDetails = new AmanStudentCollegeDetails();
                $amanStudentCollegeDetails->setAttributes($_POST['AmanStudentCollegeDetails']);
                $amanStudentCollegeDetails->setAttribute('student_details_id', $amanStudentDetails->id);
                $amanStudentCollegeDetails->save(false);
                //

                $amanStudentCourseDetails = new AmanStudentCourseDetails();
                $amanStudentCourseDetails->setAttributes($_POST['AmanStudentCourseDetails']);
                $amanStudentCourseDetails->setAttribute('student_details_id', $amanStudentDetails->id);
                $amanStudentCourseDetails->save(false);
                echo 1;
            } else {
                echo 0;
            }
        }

        die;
    }

    // Uncomment the following methods and override them if needed
    /*
      public function filters()
      {
      // return the filter configuration for this controller, e.g.:
      return array(
      'inlineFilterName',
      array(
      'class'=>'path.to.FilterClass',
      'propertyName'=>'propertyValue',
      ),
      );
      }

      public function actions()
      {
      // return external action classes, e.g.:
      return array(
      'action1'=>'path.to.ActionClass',
      'action2'=>array(
      'class'=>'path.to.AnotherActionClass',
      'propertyName'=>'propertyValue',
      ),
      );
      }
     */
}